package com.example.common.utils;

import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

@Component
public class StringUil {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /*
    * 将set格式的字符串传换为正常set集合
    * */
    public static Set<Long> stringToSet(String stringSet){
        String substrArray = stringSet.substring(1, stringSet.length() - 1);
        if (StringUtil.isNullOrEmpty(substrArray)){
            System.out.println(substrArray);
            Set<Long> set = new HashSet<>();
            String[] split = substrArray.split(",");
            for (String s:split
                 ) {
                set.add(Long.parseLong(s.replaceAll(" ","")));
            }
            return set;
        }
        return null;
    }


}
